﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>Testing</title>
    <script src="../../Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jcountdown1.3/countdown1.3/script/jquery.jcountdown1.3.js"
        type="text/javascript"></script>
    <link href="../../Scripts/jcountdown1.3/countdown1.3/css/style.css" rel="stylesheet"
        type="text/css" />
    <script src="../../Scripts/PageCreater/Scripts/PageCreater.js" type="text/javascript"></script>
    <script type="text/javascript">
        var testPaperID;
        var courseID;
        var score;
        var time;
        var now;
        var newTime;
        var testID;

        $(document).ready(function () {
            $.ajaxSetup({ cache: false });
            var para = getUrlPara();
            var arr = para.split('_');
            testPaperID = arr[0];
            courseID = arr[1];
            score = arr[2];
            time = arr[3];
            testID = arr[4];

            $.ajax({
                url: "/Test/GetCourse",
                type: "GET",
                data: { id: courseID },
                success: function (data) {
                    $("#spCourse").append(data);
                },
                error: function (msg) {
                }
            });


            var y;
            var m;
            var d;
            var h;
            var min;
            var s;
            now = $("#txtNow").val();
            y = now.split('/')[0];
            m = now.split('/')[1];
            d = now.split('/')[2].split(' ')[0];
            h = now.split(' ')[1].split(':')[0];
            min = now.split(' ')[1].split(':')[1];
            s = now.split(' ')[1].split(':')[2];

            var tmp = time / 60;
            var tmpH = tmp.toString().split('.')[0];
            var tmpM = tmp.toString().split('.')[1];
            var newH = parseInt(h) + parseInt(tmpH);
            var newM = parseInt(tmpM) * 6;
            if (parseInt(newM) + parseInt(min) >= 60) {
                newH++;
                newM = parseInt(min) + parseInt(newM) - 60;
            }
            newTime = y + "/" + m + "/" + d + " " + newH + ":" + newM + ":" + s;
            $("#time").countdown({
                date: newTime,
                htmlTemplate: "%{h} <span class=\"cd-time\">小时</span> %{m} <span class=\"cd-time\">分钟</span> %{s} <span class=\"cd-time\">秒</span>",
                onChange: function (event, timer) {

                },
                onComplete: function (event) {
                    alert("时间结束，系统将为你自动交卷！");
                    SubmitPageSubmitPage();
                },
                onPause: function (event, timer) {
                    $(this).html("Pause");
                },
                onResume: function (event) {
                    $(this).html("Resumed");
                },
                leadingZero: true
            });
            CreatePaper();
        })
        function CreatePaper() {
            $.ajax({
                url: "/Test/GetTestPaperByID",
                type: "GET",
                data: { id: testPaperID },
                dataType: "JSON",
                success: function (json) {
                    for (var i = 0; i < json.length; i++) {
                        var tmp = 1;
                        $("#divPaper").append("<div>&nbsp;&nbsp;&nbsp;<span id='type" + i + "'>第" + (parseInt(i) + 1) + "大题，共" + json[i].score + "分</span></div>");
                        for (var j = 0; j < json[i].chi.length; j++) {
                            $("#divPaper").append("<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span id='que" + j + "'>" + tmp + "." + json[i].chi[j].name + "</span></div>");
                            for (var z = 0; z < json[i].chi[j].chi.length; z++) {
                                $("#divPaper").append("<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='radio' name='qa" + json[i].chi[j].id + "' score='" + json[i].chi[j].chi[z].score + "' isTrue='" + json[i].chi[j].chi[z].isTrue + "' /><span id='ans" + z + "'>" + json[i].chi[j].chi[z].index + "." + json[i].chi[j].chi[z].content + "</span></div>")
                            }
                        }
                    }
                },
                error: function (msg) {
                }
            });
        }

        function SubmitPage() {
            var score = 0;
            $("input:radio[checked='true']", "#divPaper").each(function () {
                if ($(this).attr("isTrue") == "True") {
                    score += parseInt($(this).attr("score"));
                }
            });
            $.post("/Test/CreateScore", { score: score, testID: testID }, function () {
                alert("交卷成功！")
            })
        }
    </script>
</head>
<body>
    <div>
        <span>你还剩：</span><span id="time" style="color:Red"></span><span>分钟完成答题</span>
    </div>
    <div>
        <span>考试科目：</span><span id="spCourse" style="color:Red"></span>
    </div>
    <div id="divPaper"></div>
    <div>
        <input type="button" value="交卷" onclick="SubmitPage()" />
    </div>
    <input id="txtNow" type="hidden" value='@TempData["Now"]' />
</body>
</html>
